package hgin

import (
	"github.com/gin-gonic/gin"
	"strings"
)

func RemoteIP(ctx *gin.Context) (ip string) {
	// 从代理转发的IP字符串中取第一个真实IP
	xff := ctx.Request.Header.Get("X-Forwarded-For")
	if xff != "" {
		ip = strings.Split(xff, ",")[0]
	}
	if ip != "" {
		return
	}
	ip = ctx.Request.Header.Get("X-Real-IP")
	if ip != "" {
		return
	}
	return ctx.RemoteIP()
}
